"use strict";

const { series, src, dest } = require("gulp");
const sass = require("gulp-dart-sass");
const autoprefixer = require("gulp-autoprefixer");
const cssmin = require("gulp-cssmin");
function deepClone(obj, hash = new WeakMap()) {
	if (obj === null) return null;
	if (typeof obj !== "object") return obj;
	if (hash.has(obj)) return hash.get(obj);

	let clone = new obj.constructor();
	hash.set(obj, clone);

	for (let key in obj) {
		if (obj.hasOwnProperty(key)) {
			if (typeof obj[key] === "object") {
				clone[key] = deepClone(obj[key], hash);
			} else {
				clone[key] = obj[key];
			}
		}
	}
	return clone;
}

function compile() {
	return src("./src/index.scss")
		.pipe(sass.sync().on("error", sass.logError))
		.pipe(
			autoprefixer({
				overrideBrowserslist: ["ie > 9", "last 2 versions"],
				cascade: false,
			})
		)
		.pipe(cssmin())
		.pipe(dest("./lib"));
}

function copyfont() {
	return src("./src/fonts/**").pipe(cssmin()).pipe(dest("./lib/fonts"));
}

exports.build = series(compile, copyfont);

// 递归
function deep(arr) {
	let result = [];
	arr.forEach((item) => {
		if (Array.isArray(item)) {
			result = result.concat(deep(item));
		} else {
			result.push(item);
		}
	});
	return result;
}
